package clientcore;


import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

public class Question {

    // Question Information
    private short question_id;
    private short answer;
    private String alloptions;
    private List<String> options;
    private String hint;
    private int points;
    private String text;
    private int time;
    private String topic_id;
    private String topic;
    private short type;
    // Log Information
    private String log_time;
    // Other Information
    private Vector<Boolean> optionStatus;
    private short choice;
    private boolean status;

    public Question(short question_id) {
        this.question_id = question_id;
        choice = -1;
    }

    public Question(Question question) {
        question_id = question.getID();
        answer = question.getAnswer();

        options = new ArrayList<String>(question.getOptions());

        hint = question.getHint();
        points = question.getPoints();
        text = question.getText();
        time = question.getTime();
        topic_id = question.getTopicID();
        topic = question.getTopic();
        type = question.getType();

        log_time = question.getLogTime();

        optionStatus = new Vector<Boolean>();

        for (int i = 0; i < options.size(); i++) {
            optionStatus.add(true);
        }

        choice = -1;
    }

    public short getAnswer() {
        return answer;
    }

    public short setAnswer(short answer) {
        return this.answer = --answer;
    }

    public Vector<Integer> getAvailableOptions() {
        Vector<Integer> availableOptions = new Vector<Integer>();

        for (int i = 0; i < options.size(); i++) {
            if (optionStatus.get(i)) {
                availableOptions.add(i);
            }
        }

        return availableOptions;
    }

    public short getID() {
        return question_id;
    }

    public short setID(short question_id) {
        return this.question_id = question_id;
    }

    public String getAllOptions() {
        return alloptions;
    }

    public String setAllOptions(String allopt) {
        return this.alloptions = allopt;
    }

    public boolean getOptionStatus(int index) {
        return optionStatus.get(index);
    }

    public boolean setOptionStatus(int index, boolean status) {
        return optionStatus.set(index, status);
    }

    public List<String> getOptions() {
        return options;
    }

    public List<String> setOptions(List<String> options) {
        optionStatus = new Vector<Boolean>();

        for (int i = 0; i < options.size(); i++) {
            optionStatus.add(true);
        }

        return this.options = options;
    }

    public String getHint() {
        return hint;
    }

    public String setHint(String hint) {
        return this.hint = hint;
    }

    public int getPoints() {
        return points;
    }

    public int setPoints(int points) {
        return this.points = points;
    }

    public String getPreparedOptions() {
        String preparedOptions = "";

        if (type == 1) {
            preparedOptions += options.get(0) + "<sep>";
            preparedOptions += options.get(1);
        } else if (type == 2) {
            preparedOptions += options.get(0) + "<sep>";
            preparedOptions += options.get(1) + "<sep>";
            preparedOptions += options.get(2) + "<sep>";
            preparedOptions += options.get(3);
        }

        return preparedOptions;
    }

    public String getPreparedOptionsStatus() {
        String preparedOptionStatus = "";

        for (Boolean status : optionStatus) {
            if (status) {
                preparedOptionStatus += "1";
            } else {
                preparedOptionStatus += "0";
            }
        }

        return preparedOptionStatus;
    }

    public String getText() {
        return text;
    }

    public String setText(String text) {
        return this.text = text;
    }

    public int getTime() {
        return time;
    }

    public int setTime(int time) {
        return this.time = time * 1000;
    }

    public String getTopicID() {
        return topic_id;
    }

    public String setTopicID(String topic_id) {
        return this.topic_id = topic_id;
    }

    public String getTopic() {
        return topic;
    }

    public String setTopic(String topic) {
        return this.topic = topic;
    }

    public short getType() {
        return type;
    }

    public short setType(short type) {
        return this.type = type;
    }

    public String getLogTime() {
        return log_time;
    }

    public String setLogTime(String log_time) {
        return this.log_time = log_time;
    }

    public short getChoice() {
        return choice;
    }

    public short setChoice(short choice) {
        return this.choice = choice;
    }

    public boolean getStatus() {
        return status;
    }

    public boolean setStatus(boolean status) {
        return this.status = status;
    }
}
